// const webpack = require('webpack')

const vendors = [
  'antd',
  'react',
  'react-dom',
  'react-redux',
  'react-router',
  'redux',
  'redux-thunk',
  '@ant-design/icons',
  'lodash',
]

// module.exports = {
//   output: {
//     path: 'build',
//     filename: '[name].[chunkhash].js',
//     library: '[name]_[chunkhash]',
//   },
//   entry: {
//     vendor: vendors,
//   },
//   plugins: [
//     new webpack.DllPlugin({
//       path: 'manifest.json',
//       name: '[name]_[chunkhash]',
//       context: __dirname,
//     }),
//   ],
// }

const path = require('path')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
// dll文件存放的目录
const dllPath = 'public/vendor'
module.exports = {
  entry: {
    // 需要提取的库文件、、、、
    vendor: vendors,
  },
  output: {
    path: path.join(__dirname, dllPath),
    filename: '[name].dll.js',
    // vendor.dll.js中暴露出的全局变量名
    // 保持与 webpack.config.js中使用的webpack.DllPlugin 中名称一致
    library: '[name]_lib',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
    ],
  },
  plugins: [
    // 清除之前的dll文件
    // "clean-webpack-plugin": "^3.0.0"
    new CleanWebpackPlugin(),
    // 设置环境变量
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: 'production',
      },
    }),
    // manifest.json 描述动态链接库包含了哪些内容
    new webpack.DllPlugin({
      path: path.join(__dirname, dllPath, '[name]-manifest.json'),
      // 保持与 output.library 中名称一致
      name: '[name]_lib',
      context: process.cwd(),
    }),
  ],
}
